package likou.bisai._20210516;

import likou.offer._27;

import java.lang.reflect.Constructor;

/**
 * @author: 唐小尊
 * @email: 1171702529@qq.com
 * @cate: 2021/05/16 10:50
 */
public class _2 {
    public static void main(String[] args) {
        System.out.println(minSwaps("1110000000100001010100101010000101010101001000001110101000010111101100000111110001000111010111101100001100001001100101011110100011111100000000100011111011110111111011110111010100111101011111111101101100101010110000011110110100101111000100000001100000"));
    }

    public static int minSwaps(String s) {
        char[] sc = s.toCharArray();
        int len = sc.length;
        int oneNum = 0;
        for (char c : sc) {
            if (c == '1') {
                oneNum++;
            }
        }
        int twoNum = len - oneNum;
        if (Math.abs(twoNum - oneNum) > 1) {
            return -1;
        }
        char temp1 = '1';
        char temp2 = '0';
        int res1 = 0;
        int res2 = 0;
        if (twoNum > oneNum) {
            temp1 = '0';
        }
        if (oneNum > twoNum) {
            temp2 = '1';
        }
        for (int i = 0; i < len; i += 2) {
            if (sc[i] != temp1) {
                res1++;
            }
            if (sc[i] != temp2) {
                res2++;
            }
        }
        return Math.min(res1, res2);
    }
}
